﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace WeChatGZHTextExtractor.DB
{
    public class DataItem<T>
    {
        public T Data { get; set; }
    }

    public class SystemDataModel : BaseModel
    {
        public string Key { get; set; }

        public string Value { get; set; }

        public T Get<T>()
        {
            if (string.IsNullOrEmpty(Value))
                return default(T);

            var system_data = JsonConvert.DeserializeObject<DataItem<T>>(Value);
            if (system_data == null)
                return default(T);

            return system_data.Data;
        }

        public void Set<T>(T data)
        {
            var db_item = new DataItem<T> { Data = data };
            Value = JsonConvert.SerializeObject(db_item);
        }
    }
}
